package com.saltedfish.tool.ui.flag.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.saltedfish.tool.R;

import java.util.List;

import cn.droidlover.xdroidmvp.base.SimpleListener;


public class SelectDayAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {

    private SimpleListener listener;

    private Context mContext;

    //默认不显示常用天数设置
    private int selectPosition = 10;

    public void setListener(SimpleListener listener) {
        this.listener = listener;
    }

    public SelectDayAdapter(List<Integer> data, Context context) {
        super(R.layout.layout_select_day, data);
        this.mContext = context;
    }

    public void setSelectPosition(int position){
        this.selectPosition = position;
        notifyDataSetChanged();

    }


    @Override
    protected void convert(BaseViewHolder helper, final Integer text) {
        TextView viewSelect = helper.getView(R.id.view_select);
        viewSelect.setText(text + "天");
        int position = helper.getAdapterPosition();

        if(position == selectPosition){
            viewSelect.setTextColor(mContext.getResources().getColor(R.color.color_white));
            viewSelect.setBackgroundResource(R.drawable.shape_radius_3097_8dp);
        }else{
            viewSelect.setTextColor(mContext.getResources().getColor(R.color.color_333333));
            viewSelect.setBackgroundResource(R.drawable.shape_radius_white_e1e4_8dp);
        }

        viewSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(listener !=null){
                    listener.onClick(position);
                    setSelectPosition(position);
                }
            }
        });


    }


}
